; Music of Mercs (1991) (U.S. Gold)
; Ripped by Megachur the 17/12/2006

	write "MERCS.BIN"

music_date_rip	equ &11a6
music_adr	equ &f491
first_theme	equ 1 
last_theme	equ 2

	read "music_header_v1_0.asm"

;
.init_music	; added by Megachur
;
	ld c,1
	jp real_init_music

	jp lfb3c
	jp lfad3        ; init music
	jp lfdb8        ; play music

.lf4a0 equ $ + 1
.lf49f
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00
	dw #0e29,#0d5d,#0c9c,#0be7
	dw #0b3c,#0a9b,#0a02,#0973
	dw #08eb,#086b,#07f2,#0780
	dw #0714,#06ae,#064e,#05f4
	dw #059e,#054d,#0501,#04b9
	dw #0475,#0435,#03f9,#03c0
	dw #038a,#0357,#0327,#02fa
	dw #02cf,#02a7,#0281,#025d
	dw #023b,#021b,#01fc,#01e0
	dw #01c5,#01ac,#0194,#017d
	dw #0168,#0153,#0140,#012e
	dw #011d,#010d,#00fe,#00f0
	dw #00e2,#00d6,#00ca,#00be
	dw #00b4,#00aa,#00a0,#0097
	dw #008f,#0087,#007f,#0078
	dw #0071,#006b,#0065,#005f
	dw #005a,#0055,#0050,#004c
	dw #0047,#0043,#0040,#003c
	dw #0039,#0035,#0032,#0030
	dw #002d,#002a,#0028,#0026
	dw #0024,#0022,#0020,#001e
	dw #001c,#001b,#0019,#0018
	dw #0016,#0015,#0014,#0013
	dw #0012,#0011,#0010,#000f
.lf578
	db #0d,#1b,#01,#00,#01,#0f,#0f,#0f
	db #0f,#0e,#0e,#0d,#0d,#0c,#0b,#0b
	db #0a,#09,#09,#08,#08,#07,#07,#06
	db #06,#05,#05,#04,#03,#02,#01,#00
	db #3c,#3c,#3c,#3c,#3c,#32,#32,#32
	db #32,#32,#32,#2d,#2d,#2d,#28,#28
	db #28,#28,#23,#23,#1e,#1e,#19,#14
.lf5b4 equ $ + 4
	db #0f,#0a,#05,#00,#0d,#07,#01,#00
	db #01,#0f,#0e,#0d,#0c,#0b,#0a,#00
.lf5c7 equ $ + 7
	db #6e,#5a,#5a,#5a,#1e,#1e,#00,#13
	db #10,#60,#00,#01,#0e,#0d,#0c,#0c
	db #0b,#0b,#0a,#0a,#0a,#09,#09,#09
	db #08,#07,#06,#00,#04,#00,#fc,#00
	db #04,#00,#fc,#00,#04,#00,#fc,#00
.lf5ec equ $ + 4
	db #02,#00,#02,#00,#13,#15,#e0,#00
	db #01,#0f,#0e,#0e,#0e,#0d,#0d,#0c
	db #0c,#0c,#0c,#0c,#0b,#0b,#0b,#0b
	db #0a,#0a,#09,#09,#08,#00,#f4,#0c
	db #00,#f4,#0c,#00,#f8,#08,#00,#f8
	db #04,#04,#00,#04,#04,#00,#02,#02
.lf61b equ $ + 3
	db #02,#02,#00,#13,#02,#8a,#00,#01
.lf624 equ $ + 4
	db #0f,#00,#00,#00,#0d,#07,#01,#01
	db #00,#0d,#0d,#0d,#0c,#0c,#0c,#00
.lf637 equ $ + 7
	db #d8,#d8,#28,#28,#e2,#1e,#00,#0d
	db #05,#1a,#01,#00,#0a,#07,#05,#03
.lf646 equ $ + 6
	db #00,#03,#05,#07,#09,#00,#13,#03
	db #01,#01,#00,#0f,#0d,#00,#f8,#08
.lf651 equ $ + 1
	db #00,#13,#02,#01,#01,#00,#00,#00
.lf65a equ $ + 2
	db #00,#00,#13,#09,#01,#01,#00,#0f
	db #0e,#0d,#0d,#0c,#0c,#0c,#0c,#00
	db #00,#fe,#00,#02,#00,#02,#00,#00
.lf671 equ $ + 1
	db #00,#13,#10,#01,#01,#00,#0d,#0d
	db #0d,#0d,#0c,#0c,#0c,#0c,#0c,#0c
	db #0c,#0d,#0d,#0d,#0d,#ff,#00,#ff
	db #00,#01,#00,#ff,#00,#01,#00,#ff
.lf696 equ $ + 6
	db #00,#01,#00,#00,#00,#00,#13,#0b
	db #01,#01,#00,#0d,#0c,#0c,#0c,#0c
	db #0c,#0c,#0c,#0c,#0c,#00,#00,#ff
	db #00,#01,#00,#ff,#00,#01,#00,#ff
.lf6b1 equ $ + 1
	db #00,#13,#0b,#01,#01,#00,#0e,#0d
	db #0c,#0c,#0c,#0c,#0c,#0c,#0c,#0c
	db #00,#00,#ff,#00,#01,#00,#ff,#00
	db #01,#00,#ff,#00,#84,#23,#ff,#94
	db #80,#0b,#10,#81,#23,#10,#80,#0b
	db #08,#23,#08,#81,#23,#08,#86,#23
	db #08,#94,#83,#00,#60,#94,#83,#00
	db #74,#94,#83,#00,#40,#94,#83,#00
	db #14,#94,#83,#00,#18,#94,#80,#0b
	db #18,#81,#23,#18,#80,#0b,#0c,#0b
	db #0c,#81,#23,#18,#94,#85,#39,#06
	db #3b,#0c,#84,#3c,#6f,#85,#3d,#03
	db #3e,#0c,#3c,#0c,#3e,#0c,#40,#06
	db #41,#06,#40,#06,#3e,#06,#39,#06
	db #3b,#0c,#84,#3c,#6c,#85,#44,#03
	db #45,#0f,#43,#0c,#45,#0c,#3f,#0c
	db #3e,#06,#3c,#06,#94,#88,#28,#1e
	db #28,#12,#27,#0c,#27,#0c,#26,#18
	db #25,#18,#2a,#12,#23,#18,#1e,#06
	db #20,#06,#1e,#06,#20,#06,#23,#06
	db #94,#85,#9e,#03,#43,#04,#48,#04
	db #3c,#04,#9d,#43,#04,#48,#04,#94
	db #82,#17,#10,#17,#08,#17,#08,#17
	db #08,#17,#08,#17,#08,#17,#08,#17
	db #10,#17,#10,#17,#10,#17,#10,#94
	db #82,#14,#10,#14,#08,#14,#08,#14
	db #08,#14,#08,#14,#08,#14,#08,#13
	db #10,#13,#08,#13,#08,#13,#08,#13
	db #08,#13,#08,#13,#08,#94,#83,#00
	db #ff,#84,#2f,#80,#34,#80,#39,#80
	db #3d,#68,#40,#08,#3f,#08,#3d,#08
	db #3f,#ff,#94,#83,#00,#ff,#94,#84
	db #3f,#10,#3e,#08,#3f,#08,#41,#08
	db #43,#58,#3f,#10,#3e,#08,#3f,#08
	db #3a,#08,#37,#58,#3c,#08,#3e,#08
	db #3f,#08,#43,#28,#3e,#08,#3f,#08
	db #41,#08,#46,#18,#94,#84,#48,#18
	db #46,#18,#48,#10,#43,#08,#41,#08
	db #3f,#08,#41,#10,#3f,#08,#3e,#08
	db #3a,#18,#94,#84,#48,#80,#94,#84
	db #48,#80,#3c,#18,#3e,#18,#3f,#10
	db #41,#18,#3f,#18,#3e,#10,#3f,#18
	db #3e,#18,#3c,#10,#3e,#08,#3c,#10
	db #3a,#28,#3c,#18,#3e,#18,#3f,#10
	db #41,#18,#3f,#18,#41,#10,#3e,#08
	db #3f,#08,#3e,#08,#3c,#18,#3a,#08
	db #3c,#18,#3f,#10,#3e,#08,#3f,#18
	db #3c,#18,#3e,#18,#3f,#10,#41,#18
	db #3f,#18,#3e,#10,#3f,#18,#3e,#18
	db #3c,#10,#3e,#08,#3c,#10,#3a,#28
	db #94,#84,#3c,#18,#3e,#18,#3f,#10
	db #3c,#18,#3e,#18,#3f,#10,#3e,#20
	db #3f,#20,#41,#20,#43,#30,#94,#83
	db #9e,#ff,#00,#80,#9d,#94,#82,#24
	db #18,#22,#18,#24,#10,#2b,#08,#29
	db #08,#27,#08,#29,#10,#27,#08,#26
	db #08,#22,#08,#94,#82,#14,#18,#14
	db #08,#14,#08,#14,#10,#14,#08,#14
	db #18,#14,#08,#14,#08,#14,#10,#14
	db #08,#94,#82,#13,#18,#13,#08,#13
	db #08,#13,#10,#13,#08,#0c,#40,#94
	db #82,#14,#18,#14,#08,#14,#08,#14
	db #10,#14,#08,#15,#18,#15,#08,#15
	db #08,#15,#10,#15,#08,#17,#18,#17
	db #08,#17,#08,#17,#10,#17,#08,#13
	db #40,#94
.lf8ba
	db #95,#01,#01,#cc,#f6,#95,#01,#00
	db #e2,#f6,#95,#01,#01,#51,#f7,#95
	db #01,#00,#e6,#f6,#95,#01,#00,#e2
	db #f6,#95,#01,#01,#51,#f7,#95,#01
	db #00,#e6,#f6,#95,#06,#00,#d0,#f6
	db #95,#01,#01,#ea,#f6,#95,#01,#01
	db #51,#f7,#95,#01,#01,#ee,#f6,#95
.lf8f7 equ $ + 5
	db #28,#00,#d0,#f6,#ff,#95,#08,#0d
	db #60,#f7,#95,#05,#0e,#60,#f7,#95
	db #01,#0c,#60,#f7,#95,#01,#0d,#78
	db #f7,#95,#01,#01,#5e,#f8,#95,#01
	db #0e,#60,#f7,#95,#01,#0c,#60,#f7
	db #95,#01,#0d,#78,#f7,#95,#01,#0e
	db #60,#f7,#95,#01,#0d,#74,#f8,#95
	db #01,#0c,#74,#f8,#95,#01,#0d,#74
	db #f8,#95,#01,#0d,#8a,#f8,#95,#01
	db #0d,#74,#f8,#95,#01,#0c,#74,#f8
	db #95,#01,#0d,#98,#f8,#95,#01,#0e
	db #60,#f7,#95,#01,#0c,#60,#f7,#95
	db #01,#0d,#78,#f7,#95,#01,#01,#5e
	db #f8,#95,#01,#0e,#60,#f7,#95,#01
	db #0c,#60,#f7,#95,#01,#0d,#78,#f7
.lf970 equ $ + 6
	db #95,#01,#0e,#60,#f7,#ff,#95,#01
	db #01,#96,#f7,#95,#01,#01,#ab,#f7
	db #95,#01,#01,#af,#f7,#95,#01,#01
	db #d5,#f7,#95,#01,#01,#af,#f7,#95
	db #01,#01,#ef,#f7,#95,#01,#01,#41
	db #f8,#95,#01,#01,#af,#f7,#95,#01
	db #01,#d5,#f7,#95,#01,#01,#af,#f7
.lf9a8 equ $ + 6
	db #95,#01,#01,#eb,#f7,#ff,#95,#01
	db #01,#f2,#f6,#95,#0a,#01,#f6,#f6
.lf9b8 equ $ + 6
	db #95,#01,#01,#57,#f8,#fe,#95,#01
	db #01,#f2,#f6,#95,#02,#01,#35,#f7
	db #95,#02,#02,#35,#f7,#95,#01,#01
.lf9cd equ $ + 3
	db #57,#f8,#fe,#95,#01,#00,#05,#f7
	db #95,#01,#01,#05,#f7,#ff
.lf9d8
	dw lf8ba,lf8f7,lf970,lf9a8
.lf9e2 equ $ + 2
	dw lf9b8,lf9cd,#0000
.lf9e6
	dw lf646,lf624,lf65a,lf651
	dw lf671,lf696,lf637,lf671
.lf9f6
	dw lf6b1,#0000
.lf9fa
	dw lf578,lf5b4,lf5c7,lf5ec
.lfa06 equ $ + 4
	dw lf5ec,lf5ec,lf61b,#0000
.lfa0a
	jp lfdf0
.lfa13 equ $ + 6
.lfa11 equ $ + 4
.lfa10 equ $ + 3
.lfa0f equ $ + 2
.lfa0e equ $ + 1
.lfa0d
	db #00,#00,#00,#00,#00,#00,#00,#00
.lfa1b equ $ + 6
.lfa19 equ $ + 4
	db #00,#00,#00,#00,#00,#00,#00,#00
.lfa23 equ $ + 6
	db #00,#00,#00,#00,#00,#00,#00,#00
.lfa2b equ $ + 6
.lfa29 equ $ + 4
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
.lfa43 equ $ + 6
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#01,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#02,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
.lfa8b equ $ + 6
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#01,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#02,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00
.lfad3
	push de
	push bc
	push hl
	push ix
	push iy
	call lfae5
	pop iy
	pop ix
	pop hl
	pop bc
	pop de
	ret
;
.real_init_music
.lfae5
;
	ld (lfa0d),a
	ld a,c                  ; c = 1
	ld (lfa0e),a
	ld a,(lfa0d)
	ld iy,lfa23
	cp #ff
	jp z,lfcb2
	dec a
	jp m,lfc0f
	call lfc0f
	ld a,#01
	ld (lf49f),a
	call lfba9
	ld a,(lfa0d)
	dec a
	ld e,a
	add a
	add e
	add a
	ld e,a
	ld d,#00
	ld hl,lf9d8
	add hl,de
	ex de,hl
	ld hl,lf9e2
	sbc hl,de
	jp c,lfc0f
	ex de,hl
	ld ix,lfa43
	ld b,#03
.lfb26
	ld e,(hl)
	inc hl
	ld d,(hl)
	inc hl
	ld (ix+#0c),e
	ld (ix+#0d),d
	ld (ix+#0a),#01
	ld de,#0018
	add ix,de
	djnz lfb26
	ret
.lfb3c
	push de
	push bc
	push hl
	push ix
	push iy
	call lfb4e
	pop iy
	pop ix
	pop hl
	pop bc
	pop de
	ret
.lfb4e
	ld iy,lfa13
	ld ix,lfa8b
	ld (lfa0f),a
	dec a
	jp m,lfc3e
	add a
	ld e,a
	ld d,#00
	ld hl,lf9fa
	add hl,de
	ex de,hl
	ld hl,lfa06
	sbc hl,de
	ret c
	ex de,hl
	ld e,(hl)
	inc hl
	ld d,(hl)
	ex de,hl
	ld b,#03
	ld ix,lfa8b
	ld a,(lfa0f)
	ld c,a
	ld de,#0018
.lfb7e
	ld a,(ix+#09)
	cp c
	jr nz,lfb8e
	ld a,(ix+#05)
	and a
	jr z,lfb8e
	inc a
	jp nz,lfc5c
.lfb8e
	add ix,de
	djnz lfb7e
	ld ix,lfa8b
	ld de,#0004
	add hl,de
	ld c,(hl)
	and a
	sbc hl,de
	call lfbeb
	ld a,(ix+#05)
	cp c
	ret nc
	jp lfc5c
.lfba9
	push ix
	ld ix,lfa8b
	ld hl,lfa1b
	ld a,(lfa0e)
	ld c,a
	xor a
	ld de,#0018
.lfbba
	dec c
	jp m,lfbc5
	ld (ix+#05),#ff
	ld (hl),#00
	inc hl
.lfbc5
	add ix,de
	inc a
	cp #03
	jr c,lfbba
	pop ix
	ret
.lfbcf
	push ix
	ld ix,lfa8b
	ld b,#03
	ld de,#0018
.lfbda
	ld a,(ix+#05)
	inc a
	jr nz,lfbe4
	ld (ix+#05),#00
.lfbe4
	add ix,de
	djnz lfbda
	pop ix
	ret
.lfbeb
	push iy
	push ix
	pop iy
	ld de,#0018
	ld a,(iy+#05)
	cp (ix+#1d)
	jr c,lfbfe
	add iy,de
.lfbfe
	ld a,(iy+#05)
	cp (ix+#35)
	jr c,lfc08
	add iy,de
.lfc08
	push iy
	pop ix
	pop iy
	ret
.lfc0f
	ld ix,lfa43
	ld b,#03
	ld hl,lfa2b
	ld de,#0018
	ld a,#00
.lfc1d
	ld (hl),a
	inc hl
	ld (ix+#05),a
	ld (ix+#0e),a
	ld (ix+#0f),a
	ld (ix+#13),a
	ld (ix+#14),a
	ld (ix+#06),a
	add ix,de
	djnz lfc1d
	ld (lfa10),a
	ld (lf49f),a
	jp lfbcf
.lfc3e
	ld b,#03
	ld ix,lfa8b
	ld hl,lfa1b
	ld de,#0018
.lfc4a
	ld (hl),#00
	inc hl
	ld a,(ix+#05)
	inc a
	jr z,lfc57
	ld (ix+#05),#00
.lfc57
	add ix,de
	djnz lfc4a
	ret
.lfc5c
	ld (ix+#06),#00
	ld (ix+#03),l
	ld (ix+#04),h
	ld a,(hl)
	inc hl
	ld (ix+#07),a
	ld a,(hl)
	inc hl
	ld (ix+#08),a
	ld a,(hl)
	inc hl
	ld (ix+#01),a
	ld a,(hl)
	inc hl
	ld (ix+#02),a
	ld a,(hl)
	ld (ix+#05),a
	ld a,(lfa0f)
	ld (ix+#09),a
	ld a,(ix+#07)
	ld c,#00
	rra
	rra
	rra
	rra
	rl c
	sla c
	sla c
	rra
	rl c
	ld b,#09
	ld e,(ix+#00)
.lfc9b
	dec e
	jp m,lfca5
	sla b
	sla c
	jr lfc9b
.lfca5
	ld a,c
	xor b
	ld b,a
	ld a,c
	cpl
	and (iy+#07)
	or b
	ld (iy+#07),a
	ret
.lfcb2
	ld a,#10
	ld (lfa10),a
	ld a,c
	ld (lfa13),a
	ld a,#00
	ld (lfa11),a
	ret
.lfcc1
	ld a,(lfa10)
	and a
	ret z
	ld a,(lfa11)
	dec a
	ld (lfa11),a
	jp p,lfce6
	ld a,(lfa13)
	ld (lfa11),a
	ld a,(lfa10)
	dec a
	ld (lfa10),a
	jr nz,lfce6
	ld a,#00
	ld c,#00
	jp lfae5	; modified by Megachur lfad3
.lfce6
	ld hl,lfa2b
	ld b,#03
.lfceb
	ld d,(hl)
	ld a,(lfa10)
	ld e,a
	xor a
	dec e
	jp m,lfcfa
.lfcf5
	add d
	dec e
	jp p,lfcf5
.lfcfa
	srl a
	srl a
	srl a
	srl a
	ld (hl),a
	inc hl
	djnz lfceb
	ret
.lfd07
	ld b,#03
.lfd09
	ld a,(ix+#05)
	and a
	jp z,lfdae
	inc a
	jp z,lfdae
	ld l,(ix+#03)
	ld h,(ix+#04)
	ld a,(ix+#06)
	add #05
	ld e,a
	ld d,#00
	add hl,de
	bit 0,(ix+#07)
	jr z,lfd67
	ld a,(hl)
	cp #fe
	jr nz,lfd41
	inc (ix+#06)
	inc (ix+#06)
	inc hl
	ld a,(hl)
	push ix
	push bc
	call lfb3c
	pop bc
	pop ix
	jr lfd09
.lfd41
	cp #ff
	jr nz,lfd4b
	ld (ix+#06),#00
	jr lfd09
.lfd4b
	ld c,a
	ld a,(ix+#00)
	add #08
	ld (lfd56),a
.lfd56 equ $ + 2
	ld (iy+#00),c
	ld a,c
	and a
	jr nz,lfd61
	ld (ix+#05),#00
	jr lfdae
.lfd61
	ld e,(ix+#08)
	ld d,#00
	add hl,de
.lfd67
	bit 1,(ix+#07)
	jr z,lfda1
	ld e,(hl)
	ld d,#00
	bit 7,e
	jr z,lfd75
	dec d
.lfd75
	push hl
	ld l,(ix+#01)
	ld h,(ix+#02)
	add hl,de
	ld (ix+#01),l
	ld (ix+#02),h
	pop hl
	ld a,(ix+#00)
	add a
	ld (lfd94),a
	inc a
	ld (lfd9a),a
	ld a,(ix+#01)
.lfd94 equ $ + 2
	ld (iy+#00),a
	ld a,(ix+#02)
.lfd9a equ $ + 2
	ld (iy+#00),a
	ld e,(ix+#08)
	ld d,#00
	add hl,de
.lfda1
	bit 2,(ix+#07)
	jr z,lfdab
	ld a,(hl)
	ld (iy+#06),a
.lfdab
	inc (ix+#06)
.lfdae
	ld de,#0018
	add ix,de
	dec b
	jp nz,lfd09
	ret
;
.play_music
.lfdb8
;
	push af
	push bc
	push de
	push hl
	push ix
	push iy
.lfdc0
	call lff9d
	ld a,#ff
	ld (lfa19),a
	ld (lfa29),a
	ld iy,lfa23
	ld ix,lfa43
	call lfd07
	ld iy,lfa13
	ld ix,lfa8b
	call lfd07
	call lfcc1
	call lfe10
	pop iy
	pop ix
	pop hl
	pop de
	pop bc
	pop af
	ret
.lfdf0
	ld a,e
	ld c,d
	ld b,#f4
	out (c),a
	ld b,#f6
	in a,(c)
	or #c0
	out (c),a
	and #3f
	out (c),a
	ld b,#f4
	out (c),c
	ld b,#f6
	ld c,a
	or #80
	out (c),a
	out (c),c
	ret
.lfe10
	ld iy,lfa13
	ld ix,lfa43
	ld e,#00
	call lfe99
	ld e,#01
	call lfe99
	ld e,#08
	call lfe99
	ld bc,#0018
	add ix,bc
	ld e,#02
	call lfe99
	ld e,#03
	call lfe99
	ld e,#09
	call lfe99
	ld bc,#0018
	add ix,bc
	ld e,#04
	call lfe99
	ld e,#05
	call lfe99
	ld e,#0a
	call lfe99
	ld e,#06
	ld a,(iy+#06)
	cp #ff
	jr nz,lfe5f
	ld a,(iy+#16)
	cp #ff
	jr z,lfe63
.lfe5f
	ld d,a
	call lfa0a
.lfe63
	ld ix,lfa43
	ld b,#03
	ld c,#09
	ld h,#00
	ld de,#0018
.lfe70
	ld l,(iy+#17)
	ld a,(ix+#4d)
	and a
	jr z,lfe81
	inc a
	jr z,lfe81
	ld l,(iy+#07)
	jr lfe89
.lfe81
	ld a,(ix+#05)
	and a
	jr nz,lfe89
	ld l,#ff
.lfe89
	ld a,l
	and c
	sla c
	or h
	ld h,a
	add ix,de
	djnz lfe70
	ld d,h
	ld e,#07
	jp lfa0a
.lfe99
	ld a,e
	ld (lfeb0),a
	add #10
	ld (lfea4),a
.lfea4 equ $ + 2
	ld d,(iy+#00)
	ld a,(ix+#4d)
	and a
	jr z,lfeb1
	inc a
	jr z,lfeb1
.lfeb0 equ $ + 2
	ld d,(iy+#00)
.lfeb1
	jp lfa0a
.lfeb4
	push ix
	pop iy
	ld a,(ix+#13)
	and a
	jr z,lfec3
	ld de,#0006
	add iy,de
.lfec3
	ld l,(iy+#0c)
	ld h,(iy+#0d)
	ld e,(iy+#0e)
	ld d,#00
	add hl,de
	bit 7,(hl)
	jr nz,lfeda
	inc (iy+#0e)
	inc (iy+#0e)
	ret
.lfeda
	ld a,(hl)
	cp #94
	jp z,lff2a
	cp #95
	jp z,lff3b
	cp #9d
	jp z,lff5e
	cp #9e
	jp z,lff72
	cp #ff
	jp z,lff86
	cp #fe
	jp z,lff95
	res 7,a
	add a
	ld e,a
	ld d,#00
	ld hl,lf9e6
	add hl,de
	ex de,hl
	ld hl,lf9f6
	sbc hl,de
	jr nc,lff0e
	ld de,lf9e6
.lff0e
	ex de,hl
	ld e,(hl)
	inc hl
	ld d,(hl)
	ex de,hl
	push bc
	push iy
	ld iy,lfa23
	call lfc5c
	ld (ix+#09),#ff
	pop iy
	pop bc
	inc (iy+#0e)
	jp lfeb4
.lff2a
	ld (iy+#0e),#00
	dec (ix+#0b)
	jp nz,lfeb4
	ld (ix+#13),#00
	jp lfeb4
.lff3b
	inc hl
	ld a,(hl)
	ld (ix+#0b),a
	inc hl
	ld a,(hl)
	ld (ix+#17),a
	inc hl
	ld a,(hl)
	ld (ix+#12),a
	inc hl
	ld a,(hl)
	ld (ix+#13),a
	ld a,(ix+#0e)
	add #05
	ld (ix+#0e),a
	ld (ix+#14),#00
	jp lfeb4
.lff5e
	dec (iy+#0f)
	jr nz,lff69
	inc (iy+#0e)
	jp lfeb4
.lff69
	ld a,(iy+#10)
	ld (iy+#0e),a
	jp lfeb4
.lff72
	inc (iy+#0e)
	inc (iy+#0e)
	ld a,(iy+#0e)
	ld (iy+#10),a
	inc hl
	ld a,(hl)
	ld (iy+#0f),a
	jp lfeb4
.lff86
	pop bc
	pop bc
	ld a,(lfa0e)
	ld c,a
	ld a,(lfa0d)
	call lfae5	; lfad3 modified by Megachur
	jp lfdc0
.lff95
	pop bc
	pop bc
	call lfc0f
	jp lfdc0
.lff9d
	ld a,(lf49f)
	and a
	ret z
	ld ix,lfa43
	ld b,#03
.lffa8
	dec (ix+#0a)
	jr nz,lffda
	call lfeb4
	ld a,(hl)
	and a
	jr z,lffb7
	add (iy+#11)
.lffb7
	add a
	ld e,a
	ld d,#00
	ld iy,lf4a0
	add iy,de
	ld e,(iy+#00)
	ld d,(iy+#01)
	ld (ix+#02),d
	ld (ix+#01),e
	inc hl
	ld a,(hl)
	ld (ix+#0a),a
	ld (ix+#06),#00
	ld (ix+#05),#01
.lffda
	ld de,#0018
	add ix,de
	djnz lffa8
	ret

	;org #142b
;	ld a,&01	; theme
	;ld c,#01
	;jp #f499	; init
	;di
	;push bc
	;push hl
	;push iy
	;push ix
	;push de
	;push af
	;exx
	;push bc
	;push de
	;push hl
	;exx
	;call #f496
	;exx
	;pop hl
	;pop de
	;pop bc
	;exx
	;pop af
	;pop de
	;pop ix
	;pop iy
	;pop hl
	;pop bc
	;ei
	;ret
	;jp #f49c	; play

.game_name
	db "Mercs",0
.game_year
	db "1991",0
.game_publisher
	db "U.S. Gold",0
.music_author
	db "",0
.music_comment
	db "",0

	list

	read "music_end_v1_0.asm"
